import { createStore } from '../redux'
import cloneDeep from 'lodash/cloneDeep'

const initState = {
  count: 100
}

// const reducer = (state = initState, action) => {
//   // type=='add'表示对connt数据进行修改,返回一个新的state
//   if (action.type == 'add') {
//     const newState = { ...state, count: state.count + action.payload }
//     return newState
//   }
//   return state
// }
const reducer = (state = initState, action) => {
  // 深复制
  let newState = cloneDeep(state)

  if (action.type == 'add') {
    newState.count += action.payload
  }
  return newState
}

const store = createStore(reducer)

export default store
